import path from 'path'
import { fileURLToPath, URL } from 'node:url'
import { defineConfig } from 'vite'
import vue from '@vitejs/plugin-vue'
import Components from 'unplugin-vue-components/vite'
import { VantResolver } from 'unplugin-vue-components/resolvers'
import { createSvgIconsPlugin } from 'vite-plugin-svg-icons' //svg打包

export default defineConfig({
  base: './',
  server: {
    port: 80,
    host: true
  },
  plugins: [
    vue({
      reactivityTransform: true
    }),
    Components({
      dts: false, //vant自动生成d.ts类型文件， vant本身有类型文件，不需要生成
      resolvers: [VantResolver({ importStyle: false })] //main.ts用全部引入样式，不需要重复引入样式
    }),
    createSvgIconsPlugin({
      // 指定图标文件夹，绝对路径
      iconDirs: [path.resolve(process.cwd(), 'src/icons')],
      // Specify symbolId format
      symbolId: 'icon-[dir]-[name]'
    })
  ],
  resolve: {
    alias: {
      '@': fileURLToPath(new URL('./src', import.meta.url))
    }
  }
})
